package com.ruoyi.web.controller.demo.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.controller.demo.domain.TestInlineForm;
import com.ruoyi.web.controller.demo.service.ITestInlineFormService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 行内表单Controller
 * 
 * @author ruoyi
 * @date 2023-09-08
 */
@Controller
@RequestMapping("/demo/inlineForm")
public class TestInlineFormController extends BaseController
{
    private String prefix = "demo/inlineForm";

    @Autowired
    private ITestInlineFormService testInlineFormService;

    @RequiresPermissions("demo:inlineForm:view")
    @GetMapping()
    public String inlineForm()
    {
        return prefix + "/inlineForm";
    }

    /**
     * 查询行内表单列表
     */
    @RequiresPermissions("demo:inlineForm:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TestInlineForm testInlineForm)
    {
        startPage();
        List<TestInlineForm> list = testInlineFormService.selectTestInlineFormList(testInlineForm);
        return getDataTable(list);
    }

    /**
     * 导出行内表单列表
     */
    @RequiresPermissions("demo:inlineForm:export")
    @Log(title = "行内表单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TestInlineForm testInlineForm)
    {
        List<TestInlineForm> list = testInlineFormService.selectTestInlineFormList(testInlineForm);
        ExcelUtil<TestInlineForm> util = new ExcelUtil<TestInlineForm>(TestInlineForm.class);
        return util.exportExcel(list, "行内表单数据");
    }

    /**
     * 新增行内表单
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存行内表单
     */
    @RequiresPermissions("demo:inlineForm:add")
    @Log(title = "行内表单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TestInlineForm testInlineForm)
    {
        return toAjax(testInlineFormService.insertTestInlineForm(testInlineForm));
    }

    /**
     * 修改行内表单
     */
    @RequiresPermissions("demo:inlineForm:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TestInlineForm testInlineForm = testInlineFormService.selectTestInlineFormById(id);
        mmap.put("testInlineForm", testInlineForm);
        return prefix + "/edit";
    }

    /**
     * 修改保存行内表单
     */
    @RequiresPermissions("demo:inlineForm:edit")
    @Log(title = "行内表单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TestInlineForm testInlineForm)
    {
        return toAjax(testInlineFormService.updateTestInlineForm(testInlineForm));
    }

    /**
     * 删除行内表单
     */
    @RequiresPermissions("demo:inlineForm:remove")
    @Log(title = "行内表单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(testInlineFormService.deleteTestInlineFormByIds(ids));
    }
}
